package utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.ma.App;


/**
 * @author lomasky
 * @ClassName: SharedPrefUtil
 * @Description: sharedprefrence数据
 * @data: 2016年11月2日 下午2:25:25
 * @version: V1.0
 */
public class SharedPrefUtil {

    private SharedPreferences.Editor mEditor;
    private SharedPreferences mSharedPreferences;

    public static SharedPrefUtil getInstance() {
        if (instance == null) {
            instance = new SharedPrefUtil(App.getInstance());
        }
        return instance;
    }

    public static void setInstance(SharedPrefUtil instance) {
        SharedPrefUtil.instance = instance;
    }

    static SharedPrefUtil instance;

    private SharedPrefUtil(Context context) {
        mSharedPreferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        mEditor = mSharedPreferences.edit();

    }

    public void putString(String key, String value) {
        mEditor.putString(key, value);
        mEditor.commit();
    }

    public void putInt(String key, int value) {
        mEditor.putInt(key, value);
        mEditor.commit();

    }

    public void putFloat(String key, float value) {
        mEditor.putFloat(key, value);
        mEditor.commit();
    }

    public void putLong(String key, long value) {
        mEditor.putLong(key, value);
        mEditor.commit();
    }

    public void putBoolean(String key, boolean value) {
        mEditor.putBoolean(key, value);
        mEditor.commit();
    }

    public int getInt(String key     ) {
        return mSharedPreferences.getInt(key, 0);
    }

    public boolean getBoolean(String key     ) {
        return mSharedPreferences.getBoolean(key, false);
    }

    public float getFloat(String key ) {
        return mSharedPreferences.getFloat(key, 0);
    }

    public long getLong(String key) {
        return mSharedPreferences.getLong(key, 0);
    }

    public String getString(String key ) {
        return mSharedPreferences.getString(key, "");
    }

    public void commit() {
        mEditor.commit();
    }
}
